﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Windows.Data;
using System.Windows.Media;

namespace VNet.VisiSuite.Controls
{
    public class MultiValueColorConverter : IMultiValueConverter
    {
        public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
        {
            // WORK AROUND FOR NOT BEING ABLE TO BIND TO COLOR IN FROM IN A STORYBOARD
            // see - http://stackoverflow.com/questions/2186933/wpf-animation-binding-to-the-to-attribute-of-storyboard-animation/14164245#14164245

            // To color #ff5c5c5c = 92, 92, 92
            if (values.Length != 2 || values[0] == null || values[0].GetType() != typeof(string))
                return null;


            object convert_from_string = ColorConverter.ConvertFromString((string)values[0]);
            if (convert_from_string == null)
                return null;

            Color start_color = (Color)convert_from_string;
            double progress = (double)values[1];

            //double result = 1.0;
            //for (int i = 0; i < values.Length; i++)
            //{
            //    if (values[i] is double)
            //        result *= (double)values[i];
            //}
            Color result = new Color();
            result.A = 255;
            result.R = (byte)(92 + (start_color.R - 92) * progress);
            result.G = (byte)(92 + (start_color.G - 92) * progress);
            result.B = (byte)(92 + (start_color.B - 92) * progress);

            return result;
        }

        public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
        {
            throw new Exception("Not implemented");
        }
    }

}
